/* enum */
import ComponentNameEnum from '@model/enum/ComponentNameEnum'
/* entity */
import Tag from '@model/entity/Tag/Tag'
/* vue */
// @ts-ignore
import { ComponentInstance, ComponentRenderProxy, defineComponent } from 'vue'
import { CommonComponentInstance } from '@model/VC'
import http from 'src/util/HttpUtil';

interface ChartTeamSelectSetupState {
  // 团队选择框变化事件
  handlerTeamChange: (value: Tag[]) => void;
}

enum ChartTeamSelectEventEnum {
  Input = 'input'
}

export type ChartTeamSelectProps = {
  // 团队值数组
  value: Tag[];
}
export type ChartTeamSelectInstance = ComponentInstance & ChartTeamSelectSetupState
export type ChartTeamSelectVM = ComponentRenderProxy<ChartTeamSelectProps> & CommonComponentInstance

export default defineComponent<ChartTeamSelectProps, ChartTeamSelectSetupState>({
  name: ComponentNameEnum.ChartTeamSelect,
  props: {
    value: {
      type: Array,
      default: () => []
    }
  },
  setup(props: ChartTeamSelectProps, { emit }) {
    
    /** 
     * @description 团队选择框变化事件
    */
    const handlerTeamChange = (value: Tag[]) => {
      emit(ChartTeamSelectEventEnum.Input, value)
    }

    const fetchTeam = (params: any) => {
      return http.post('/security/tag/tree', {...params, ...{authKey: 'VIP_REPORT_VIEW', source: 'dataInfo'}})
    }
    
    return {
      handlerTeamChange,
      fetchTeam
    }
  },
  render() {
    return (
      <div>
        <biz-team-select
          multiple
          collapse
          is-auto-select-child
          fetch-func={this.fetchTeam}
          value={this.value} 
          onInput={this.handlerTeamChange}
        >
        </biz-team-select>
      </div>
    )
  }
})
